//
//  MineViewController.m
//  village_ios
//
//  Created by mac on 2019/8/4.
//  Copyright © 2019 com.sw.village. All rights reserved.
//

#import "MineViewController.h"
#import "MinePartyVerfityController.h"
#import "MinePasswordChangeController.h"
#import "MineDataController.h"

#import "UserInfo.h"

typedef NS_ENUM(NSInteger,MineRow) {
    MineRowLike = 2,
    MineRowFavorite,
    MineRowDangyuanrenzheng,
    MineRowXiugaimima,
    MineRowCheck,
    MineRowCache,
    MineRowAbout
};

@interface MineViewController ()

//view
@property (weak, nonatomic) IBOutlet UIImageView *avatorImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *villageJobLabel;
@property (weak, nonatomic) IBOutlet UIImageView *partyIconView;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;

//data
@property (strong, nonatomic) UserInfo *userInfo;
@end

@implementation MineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadNetwordData];
}

- (void)loadNetwordData {
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [SYProgressHUD show];
    [APIManager requestWithUrlString:@"api/user/info" params:params method:@"GET" success:^(id response) {
        
        self.userInfo = [UserInfo mj_setKeyValues:response];
        [self loadUserInfo];
        [SYProgressHUD hide];
    } failure:^(NSError *error) {
        [SYProgressHUD hide];
    }];
}
- (void)loadUserInfo {
    self.nameLabel.text = self.userInfo.name;
    self.phoneLabel.text = self.userInfo.phone;
    self.villageJobLabel.text = self.userInfo.name;
    [self.avatorImageView setImageWithURL:[NSURL URLWithString:self.userInfo.avator] placeholderImage:[UIImage imageNamed:@"app_icon"]];
    self.partyIconView.hidden = self.userInfo.verifyId != nil;

}
- (IBAction)toChangeMineData {
    MineDataController *vc = [MineDataController instanceWithStoryBoard];
    vc.userInfo = self.userInfo;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if(indexPath.row == MineRowDangyuanrenzheng) {
        MinePartyVerfityController *vc = [MinePartyVerfityController instanceWithStoryBoard];
        [self.navigationController pushViewController:vc animated:YES];
    } else if(indexPath.row == MineRowXiugaimima) {
        MinePasswordChangeController *vc = [MinePasswordChangeController instanceWithStoryBoard];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

@end
